<?php
  session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Know Your Sentiments on FaceBook</title>
<link rel="shortcut icon" href="http://www.sentyfb.altervista.org/img/title.ico" type="image"/>
<link rel="icon" href="http://www.sentyfb.altervista.org/img/title.ico" />
</head>

<body bg bgcolor="">
<center>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<h1><font face=tondo">Know Your Sentiments</font></h1>

</center>

<h4> 

<?php
  require_once('src/facebook.php');

  $fbconfig['appid' ] = "294539840579833";
  $fbconfig['secret'] = "fa6384c4966c76b0a3de06bf0af4b2a0";
  $fbconfig['baseurl'] = "http://sentyfb.altervista.org";

  // Facebook obj initialization
  $facebook = new Facebook(array(
	'appId' => $fbconfig['appid'],
	'secret' => $fbconfig['secret'],
	'cookie' => false,
  ));
  
  // Fb obj params  
  $params = array(
  scope => 'export_stream, friends_activities, friends_checkins, friends_events, friends_groups,friends_likes, friends_online_presence,friends_status,manage_friendlists, manage_notifications, manage_pages, offline_access, publish_stream, read_friendlists, read_requestds, read_stream, status_update, user_activities, user_likes, user_status, xmpp_login',
redirect_uri => 'http://sentyfb.altervista.org/UI.php'
  );
  
  $user = $facebook->getUser();

  $facebook_s = serialize($facebook);
  
  if (!isset($_SESSION['facebook_s']));
	$_SESSION['facebook_s'] = $facebook_s;

  // Login or logout url will be needed depending on current user state.
  if ($user) {
	  $logoutUrl = $facebook->getLogoutUrl();
	  echo "<center><a href=$logoutUrl> Logout </a><center>";
  }
  else {
	  $loginUrl = $facebook->getLoginUrl($params);
	  echo "<br><center><a href=$loginUrl> Login </a></center>";	
  }

?>
</h4>
<?
  
  // We may or may not have this data based on whether the user is logged in.
  // If we have a $user id here, it means we know the user is logged into
  // Facebook, but we don't know if the access token is valid. An access
  // token is invalid if the user logged out of Facebook.
  if ($user) {
	try {
	  // Proceed knowing you have a logged in user who's authenticated.
	  $user_profile = $facebook->api('/me');

	  echo "<br> Hi <strong>".$user_profile['first_name']."!</strong>. Welcome and enjoy this sentiment analysis service! Your facebook ID is ".$user.".<br><br>";
	  
	?>
	Get your
	<a href="list.php"> friend list</a>
    
	<?
	
	
	
	  
	} catch (FacebookApiException $e) {
		error_log($e);
		echo "<br /><br />ECCEZIONE INTERCETTATA. CONTROLLARE LOG SERVER.<br />";
		echo "Reloading Page. Please wait just a few seconds";
		?>
        <br />
        <META HTTP-EQUIV="refresh" CONTENT="3"> 
        <?
	}			  
  }
?> 


</body>
</html>



